// import "../../components/basicTable.less";
// import Toolbar from "@/components/ViewComponents/Toolbar";
import { useTranslation } from "react-i18next";
import { BasicTable, useTable, BasicColumn, FormSchema } from "@/components/Table";
import { Tag, Tooltip } from "antd";
import { get_selectEmergen } from "@/api/EmergencyDictionary";
import DetailDrawer from "./DetailDrawer";
import { useDrawer } from "@/components/Drawer";

export default function admitted_to_observation() {
	const { t } = useTranslation();
	// 配置table
	const columns: BasicColumn[] = [
		{
			title: t("felix_ui.sq_numb"),
			width: 100,
			// dataIndex: "sq_numb",
			render: (text, record, index) => index * 1 + 1 // 设置序号
		},
		{
			title: t("felix_ui.patient_ID"),
			dataIndex: "patientId"
		},
		{
			title: t("felix_ui.doctor"),
			dataIndex: "doctorName"
		},
		{
			title: t("felix_ui.full_name"),
			dataIndex: "fullName",
			render: (text, record) => (
				<a
					onClick={() => {
						openDrawer(true, {
							patientId: record.patientId
						});
					}}
				>
					<Tooltip placement="left" title={t("felix_ui.view_medication_info")} color="blue">
						{text}
					</Tooltip>
				</a>
			)
		},
		{
			title: t("felix_ui.birthday"),
			dataIndex: "birthday"
		},
		{
			title: t("felix_ui.age"),
			dataIndex: "age"
		},
		{
			title: t("felix_ui.gender"),
			dataIndex: "gender"
		},
		{
			title: t("felix_ui.status"),
			dataIndex: "status",
			width: 200,
			render: (text, record) => {
				return record.status === "1" ? (
					<Tag color="success">{t("felix_ui.discharged_from_hospital")}</Tag>
				) : (
					<Tag color="error">{t("felix_ui.not_discharged_from_hospital")}</Tag>
				);
			}
		},
		{
			title: t("felix_ui.house_number"),
			dataIndex: "addrHouseno"
		},
		{
			title: t("felix_ui.village_street"),
			dataIndex: "addrWard"
		},
		{
			title: t("felix_ui.occupation"),
			dataIndex: "occupation"
		},
		{
			title: t("felix_ui.ethnicity"),
			dataIndex: "ethnicity"
		},
		{
			title: t("felix_ui.province_city"),
			dataIndex: "addrProvince"
		},
		{
			title: t("felix_ui.district"),
			dataIndex: "addrDistrict"
		},
		{
			title: t("felix_ui.ward_commune"),
			dataIndex: "addrCommune"
		},
		// {
		// 	title: t("felix_ui.admission_number"),
		// 	dataIndex: "admissionNumber"
		// },
		// {
		// 	title: t("felix_ui.impoter"),
		// 	dataIndex: "impoter"
		// },
		{
			title: t("felix_ui.department"),
			dataIndex: "deptName"
		},
		{
			title: t("felix_ui.referral_from"),
			dataIndex: "referralType"
		},
		{
			title: t("felix_ui.beneficiary"),
			dataIndex: "patSubject"
		}
		// {
		// 	title: t("felix_ui.medical_route"),
		// 	dataIndex: "medicalRoute"
		// },
		// {
		// 	title: t("felix_ui.transfer_paper"),
		// 	dataIndex: "transferPaper"
		// },
		// {
		// 	title: t("felix_ui.medication_name_dosage"),
		// 	dataIndex: "medicationNameDosage"
		// },
		// {
		// 	title: t("felix_ui.unit_of_measure"),
		// 	dataIndex: "unitOfMeasurement"
		// }
	];
	const TopFormSchema: FormSchema[] = [
		{
			label: t("felix_ui.patient_ID"),
			field: "patientId",
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.full_name"),
			field: "fullName",
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.department"),
			field: "department",
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.doctor"),
			field: "doctorName",
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.age"),
			field: "age",
			component: "Input",
			colProps: { span: 6 }
		},
		{
			label: t("felix_ui.gender"),
			field: "gender",
			component: "Select",
			colProps: { span: 6 },
			componentProps: {
				options: [
					{ label: t("felix_ui.man"), value: t("felix_ui.man") },
					{ label: t("felix_ui.woman"), value: t("felix_ui.woman") }
				]
			}
		}
	];
	const [registerDetailDrawer, { openDrawer }] = useDrawer();
	const mergeObjects = (obj1: any, obj2: any) => {
		let result = { ...obj1 };
		for (let key in obj2) {
			if (!Object.prototype.hasOwnProperty.call(result, key)) {
				result[key] = obj2[key];
			}
		}
		return result;
	};
	const getSelectList = async (data: any[]) => {
		return data ? data.map(item => mergeObjects(item, item.patients)) : [];
	};

	// 配置table
	const [registerTable] = useTable({
		title: t("felix_ui.ListRoom"),
		api: get_selectEmergen,
		columns,
		afterFetch: data => getSelectList(data),
		useSearchForm: true,
		formConfig: {
			labelWidth: 120,
			schemas: TopFormSchema,
			showActionButtonGroup: true,
			baseColProps: { span: 8 }
		}
	});

	return (
		<div className="6_12_01">
			<BasicTable register={registerTable}></BasicTable>
			<DetailDrawer register={registerDetailDrawer}></DetailDrawer>
			{/* <Toolbar action={handlerToolbarAction} btnList={btnList} /> */}
		</div>
	);
}
